/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/
#ifndef GAMEEVENTPARSER_H
#define GAMEEVENTPARSER_H

/*[[[cog
import cog
from gameeventdefs import *
]]]
[[[end]]]*/

#include "gameevents.h"
#include "xmlnode.h"

#include <QXmlStreamWriter>
#include <QSharedPointer>

/**
 * The GameEventParser class provides static methods for writing GameEvents into
 * XML streams and reading GameEvents from XML streams.
 * @author MacJariel
 */
class GameEventParser
{
public:
    /**
     * Writes GameEventData into XML stream using QXmlStreamWriter.
     */
    static void write(QXmlStreamWriter*, GameEventDataPtr);

    /**
     * Reads the GameEventData from XML stream and returns it.
     */
    static GameEventDataPtr read(XmlNode*);

private:
    static void writeCmdData(QXmlStreamWriter*, const GameEventCmdDataPtr&);
    static GameEventCmdDataPtr readCmdData(XmlNode*);

    /*[[[cog
    cog.outl("");
    for gec in GameEventCmds:
        cog.outl("static void write%(gameEventCmdName)s(QXmlStreamWriter*, const %(structName)sPtr&);" % gec)
        cog.outl("static %(structName)sPtr read%(gameEventCmdName)s(XmlNode*);" % gec)
        cog.outl("");
    ]]]*/

    static void writeMoveCard(QXmlStreamWriter*, const MoveCardCmdDataPtr&);
    static MoveCardCmdDataPtr readMoveCard(XmlNode*);

    static void writeUpdatePlayer(QXmlStreamWriter*, const UpdatePlayerCmdDataPtr&);
    static UpdatePlayerCmdDataPtr readUpdatePlayer(XmlNode*);

    static void writeUpdateGameContext(QXmlStreamWriter*, const UpdateGameContextCmdDataPtr&);
    static UpdateGameContextCmdDataPtr readUpdateGameContext(XmlNode*);

    static void writeSetPlayers(QXmlStreamWriter*, const SetPlayersCmdDataPtr&);
    static SetPlayersCmdDataPtr readSetPlayers(XmlNode*);

    //[[[end]]]
};

#endif // GAMEEVENTPARSER_H
